package com.zhny.aiot.gd.sfj.plugin.model;

import com.zhny.aiot.plugin.modbus.device.ModemDevice;
import com.zhny.aiot.plugin.modbus.handler.model.ModemResponseMessage;
import com.zhny.aiot.plugin.model.MessageEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FerilizerDiscreteResultModel extends FertilizerResultModel {
    private final Logger logger = LoggerFactory.getLogger(FerilizerDiscreteResultModel.class);
    public FerilizerDiscreteResultModel(ModemResponseMessage modemBusResponse, ModemDevice device) {
        super (modemBusResponse,device);
    }

    @Override
    protected void onDecoder(MessageEntry entry) {
        logger.info("---fertilizer writer discrete message---");
        FertilizerStoreEntry storeEntry = new FertilizerStoreEntry ();
        if(getModemBusResponse ().getData ().readUnsignedShort () == 1){
            storeEntry.setPumpStatus (true);
        }
        else{
            storeEntry.setPumpStatus (false);
        }
        entry.setData (storeEntry);
        this.getDevice ().nofity (entry);
        this.getDevice ().saveReal (storeEntry);
    }
}
